package ruifeng.zcj.dig.ui.home.change;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewHolder;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.ui.base.RefreshRecyclerFragment;
import ruifeng.zcj.dig.ui.home.MainActivity;
import ruifeng.zcj.dig.ui.home.MainActivity2;
import ruifeng.zcj.mybase.base.BaseActivity;

/**
 * Created by Administrator on 2016/9/23 0023.
 */
public class ChangeMainFragment extends RefreshRecyclerFragment {

    protected MainActivity2 mainActivity;


    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {
        showSnackBar("点击了item"+position);
        switch (position){
            case 0:
                if (mainActivity != null) {
                    mainActivity.switchFragment(1);
                }
                break;
            case 1:
                if (mainActivity != null) {
                    mainActivity.switchFragment(1);
                }
                break;
            case 2:
                if (mainActivity != null) {
                    mainActivity.switchFragment(2);
                }
                break;
            case 3:
                if (mainActivity != null) {
                    mainActivity.switchFragment(2);
                }
                break;
            case 4:
                if (mainActivity != null) {
                    mainActivity.switchFragment(3);
                }
                break;
            case 5:
                if (mainActivity != null) {
                    mainActivity.switchFragment(4);
                }
                break;
            default:
                break;

        }
    }

    /***
     * 不允许下拉刷新
     * */
    @Override
    public boolean getRefreshable() {
        hideSwipeRefreshing();
        return false;
    }

    /***
     * 是否请求数据
     * **/
    @Override
    protected boolean requestDataIfViewCreated() {
        return false;
    }

    @Override
    public boolean onRVItemLongClick(ViewGroup parent, View itemView, int position) {
        return false;
    }


    @Override
    protected void initFragmentConfig(View view) {
        super.initFragmentConfig(view);

        BaseActivity baseActivity = getBaseActivity();
        mainActivity = (MainActivity2) baseActivity;


//        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

    }

    @Override
    protected BGARecyclerViewAdapter getAdapter() {
        return new MomentAdapter(recyclerView);
    }

    public class MomentAdapter extends BGARecyclerViewAdapter<Integer> {

        int[] resImags = {
                R.drawable.shopping_h,R.drawable.wabi_h,R.drawable.zhaop_h,
                R.drawable.luntan_h,R.drawable.pingg_h,R.drawable.shic_h,
        };

        public MomentAdapter(RecyclerView recyclerView) {
            super(recyclerView, R.layout.listview_item_home);
        }

        @Override
        public void fillData(BGAViewHolderHelper helper, int position, Integer moment) {
            /*if (TextUtils.isEmpty(moment.content)) {
                helper.setVisibility(R.id.tv_item_moment_content, View.GONE);
            } else {
                helper.setVisibility(R.id.tv_item_moment_content, View.VISIBLE);
                helper.setText(R.id.tv_item_moment_content, moment.content);
            }*/

            helper.setImageResource(R.id.home_fragment_item,resImags[position]);
//            helper.setImageDrawable(R.id.home_fragment_item,)


          /*
            /*TextView postingsname = helper.getView(R.id.forum_fragment_item_text_title);

            BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.npl_item_moment_photos);

            ninePhotoLayout.init(MomentListActivity.this);
            ninePhotoLayout.setDelegate(MomentListActivity.this);
            ninePhotoLayout.setData(moment.photos);*/
        }

        @Override
        public void onViewRecycled(BGARecyclerViewHolder holder) {
            super.onViewRecycled(holder);

           /* BGANinePhotoLayout ninePhotoLayout = holder.getViewHolderHelper().getView(R.id.npl_item_moment_photos);
            ninePhotoLayout.init(null);
            ninePhotoLayout.setDelegate(null);*/
        }
    }

    int[] resImags = {
            R.drawable.shopping_h,R.drawable.wabi_h,R.drawable.zhaop_h,
            R.drawable.shic_h,R.drawable.pingg_h,R.drawable.shic_h,
    };
    ArrayList<Integer> mArrayList;
    @Override
    protected void onFirstUserVisible() {
       /* ArrayList<Drawable> mDrawables = new ArrayList<>();

        mDrawables.*/
        super.onFirstUserVisible();
        mArrayList = new ArrayList<>();
        for (int i = 0; i < resImags.length; i ++){
            mArrayList.add(resImags[i]);
        }

        mMomentAdapter.addNewData(mArrayList);

    }

    @Override
    protected void onUserVisible() {
     //   super.onUserVisible();

    }

    @Override
    protected void onUserInvisible() {

    }

    @Override
    protected void cleanMemory() {

    }
}
